<?php

class ItemMetDao extends BaseDao {
	
	public function __construct($dsn, $username, $password) {
		parent::__construct($dsn, $username, $password);
			
		$this->mapping = new Mapping("ItemMetModel", "t_item_met", "id",
			array(
				"id",
				"idRaca",
				"codigoItem",
				"nome",
				"classe",
				"alvoUm",
				"alvoDois",
				"alvoTres",
				"iniciativa",
				"qtdeArmas",
				"poderFogo",
				"fuselagem",
				"recursoMetal",
				"recursoCristal",
				"recursoEonio",
				"qtdeTick",
				"combate",
				"tad",
				"score"
			),
			array(
				"id_item",
				"id_raca",
				"codigo_item",
				"nome_item",
				"classe_item",
				"alvo_um",
				"alvo_dois",
				"alvo_tres",
				"iniciativa_item",
				"quantidade_armas",
				"poder_fogo",
				"fuselagem",
				"recurso_metal",
				"recurso_cristal",
				"recurso_eonio",
				"quantidade_ticks",
				"combate",
				"tad_item",
				"score_item"
			));
	}

	public function findByName($name) {
		$mappingInfo = $this->mapping->getMappingInfo();
		$columnName = $mappingInfo["nome"];
		$tableName = $this->mapping->getTableName();
			
		$query = "SELECT * FROM " . $tableName . " WHERE " . $columnName . "=:name;";
		
		$pdo = $this->dataSource->getPdo();
		$statement = $pdo->prepare($query);
		$statement->execute(array("name" => $name));
		$result = $statement->fetch(PDO::FETCH_ASSOC);
			
		$user = null;

		if ($result) {
			$user = $this->makeObject($result);
		}
			
		return $user;
	}
}
?>